<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" :rows="2" labelWidth="100" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      height="140px"
      columnsRef="yfkdjxzkh"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :isPagination="true"
      selectionType="single"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">取 消</el-button>
      <AjaxButton :click="closeDrawer.bind(this, 2)" type="primary" size="small">确定</AjaxButton>
    </div>
  </div>
</template>
<script>
import { queryCustomer } from '@/api/finance/advancesReceived/register';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: '',
  mixins: [dictionary],
  props: ['customerCode'],
  data() {
    return {
      fetchApi: queryCustomer, // 调用接口
      fetchParams: {
        // customerCode: this.customerCode,
        sort: '',
        order: 'asc'
      }, // 调用数据
      topFilterList: this.createTopFilters(),
      columns: this.createTablelist(),
      selectedRows: []
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close', false);
      } else {
        if (!this.selectedRows.length) {
          return this.closeDrawer(1);
        }
        this.$emit('change', this.selectedRows);
      }
    },
    createTopFilters() {
      return [
        {
          type: 'SELECT',
          label: '客户类型',
          fieldName: 'CUSTOMER_TYPE',
          placeholder: '请选择',
          itemList: [
            { text: '车主', value: '80521001' },
            { text: '业务往来客户', value: '80521002' },
            { text: '保险公司', value: '80521004' }
          ]
        },
        {
          type: 'INPUT',
          label: '客户编号',
          fieldName: 'customerCode',
          placeholder: '请输入...'
          // initialValue:this.customerCode
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          placeholder: '请输入...'
        }
      ];
    },
    createTablelist() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '客户编号',
          dataIndex: 'CUSTOMER_CODE',
          sorter: true,
          filter: true
        },
        {
          title: '客户名称',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true,
          filter: true
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true
        },
        {
          title: '地址',
          dataIndex: 'ADDRESS',
          sorter: true,
          filter: true,
          width: 300
        },
        {
          title: '邮编',
          dataIndex: 'ZIP_CODE',
          sorter: true,
          filter: true
        },
        {
          title: '联系人',
          dataIndex: 'CONTACTOR_NAME',
          sorter: true,
          filter: true,
          width: 200
        },
        {
          title: '联系人电话',
          dataIndex: 'CONTACTOR_PHONE',
          sorter: true,
          filter: true
        },
        {
          title: '联系人手机',
          dataIndex: 'CONTACTOR_MOBILE',
          sorter: true,
          filter: true
        },
        {
          title: '客户类型',
          dataIndex: 'PRE_PAY_CUS_TYPE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8052'),
          render: props => {
            return <span>{this.createDictText(props.row.PRE_PAY_CUS_TYPE, '8052')}</span>;
          }
        }
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 选中
    selectChange(rows) {
      this.selectedRows = rows;
    }
  }
};
</script>
